package org.leviatan.definator.gui.swingmodels;

import java.util.Collection;
import java.util.Iterator;

import javax.swing.table.AbstractTableModel;

import org.leviatan.definator.core.model.Record;

public class RecordTableModel extends AbstractTableModel {

	
	private static final long serialVersionUID = -6986699503826129793L;

	private String[] columnNames = {"Id","Name"};
	
	private Object[][] tableData;
	
	
	public void initData(Collection recModels) {
		this.tableData = new Object[recModels.size()][5];
		int col = 0;
		for (Iterator i = recModels.iterator(); i.hasNext(); ) {
			Record rec = (Record) i.next();
			
			String id = rec.getId();
			String name = rec.getName();
			String tblRef = rec.getTableRef();
			
			tableData[col][0] = id;
			tableData[col][1] = name;
			//tableData[col][2] = tblRef;
			
			col++;
		}
	}
	
	public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }
	
	public String getColumnName(int i) {
		return this.columnNames[i];
	}
	
	public int getColumnCount() {
		return this.columnNames.length;
	}

	public int getRowCount() {
		return tableData.length;
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		return this.tableData[rowIndex][columnIndex];
	}

}
